package com.sharepics.ws;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sharepics.bean.Album;
import com.sharepics.bean.XMLAlbum;
import com.sharepics.bean.XMLPicture;
import com.sharepics.dao.AlbumDAO;
import com.sharepics.utils.bean.BeanUtils;

@RequestMapping("/ws/album")
@Controller
public class AlbumWS {

	@Autowired
	AlbumDAO albumDAO;
	
    @RequestMapping(value="/{id}",method = RequestMethod.GET)
    @ResponseBody
    public XMLAlbum get(@PathVariable Long id) {
		Album album = albumDAO.get(id);
		XMLAlbum xmlAlbum = BeanUtils.get(album);
    	return xmlAlbum;
    	
    }
    
    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public XMLAlbum add(@RequestBody XMLAlbum xmlAlbum) {
		Album album = BeanUtils.get(xmlAlbum);
    	albumDAO.save(album);
    	XMLAlbum returnAlbum = BeanUtils.get(album);
    	return returnAlbum;
    	
    }
    
}
